<?php
require_once(_SRC_."/domain/PageTemplate.php");


class PageTemplateDao{
	
	public function getPageTemplates(){
		$con = mysql_connect(DB_HOST, DB_USER, DB_PWD);
		if (!$con){
			die('Could not connect: ' . mysql_error());
		}
		
		mysql_select_db(DB_NAME, $con);	
		$result = mysql_query("SELECT * FROM `page_template` LIMIT 0 , 30");
		
		$pageTemplates = array();
		while($row = mysql_fetch_array($result)){
			$pageTemplate = new pageTemplate($row);
			array_push($pageTemplates, $pageTemplate);
		}
		
		mysql_close($con);
		
		return $pageTemplates;
	}
	
	public function getPageTemplate($id){
		$con = mysql_connect(DB_HOST, DB_USER, DB_PWD);
		if (!$con){
			die('Could not connect: ' . mysql_error());
		}
		
		mysql_select_db(DB_NAME, $con);	
		
		$result = mysql_query("SELECT * FROM `page_template` WHERE `id`=".$id);
		while($row = mysql_fetch_array($result)){
			$pageTemplate = new pageTemplate($row);
		}
		
		return $pageTemplate;
	}
}
?>